package com.chengcang.api.modules.busi.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chengcang.api.modules.busi.dto.BusiOrderDTO;
import com.chengcang.api.modules.busi.dto.BusiOrderInfoDTO;
import com.chengcang.api.modules.busi.dto.BusiOrderPageDto;
import com.chengcang.api.modules.busi.service.BusiOrderService;
import com.chengcang.api.modules.busi.vo.BusiOrderVO;
import com.chengcang.common.constant.Constant;
import com.chengcang.common.utils.Result;
import com.chengcang.common.validator.AssertUtils;
import com.chengcang.common.validator.ValidatorUtils;
import com.chengcang.common.validator.group.AddGroup;
import com.chengcang.common.validator.group.DefaultGroup;
import com.chengcang.common.validator.group.UpdateGroup;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;



/**
 *
 *
 * @author zhanli
 * @since 1.0.0 2023-01-10
 */
@RestController
@RequestMapping("/busi/order")
@Api(tags="订单模块")
public class BusiOrderController {
    @Autowired
    private BusiOrderService busiOrderService;



    @GetMapping("/supply/page")
    @ApiOperation("订单履约分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = Constant.PAGE, value = "当前页码，从1开始", paramType = "query", required = true, dataType="int") ,
            @ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataType="int") ,
            @ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType="String") ,
            @ApiImplicitParam(name = Constant.ORDER, value = "排序方式，可选值(asc、desc)", paramType = "query", dataType="String")
    })
//    @RequiresPermissions("busi:order:page")
    public Result<Page<BusiOrderVO>> supplypage(BusiOrderPageDto busiOrderPageDto){
        return new Result<Page<BusiOrderVO>>().ok(busiOrderService.getSupplyPage(busiOrderPageDto));
    }


    @GetMapping("{id}")
    @ApiOperation("信息")
//    @RequiresPermissions("busi:order:info")
    public Result<BusiOrderVO> get(@PathVariable("id") Long id){
        BusiOrderVO data = busiOrderService.detail(id);
        return new Result<BusiOrderVO>().ok(data);
    }


    @PutMapping
    @ApiOperation("发货")
//    @LogOperation("发货")
//    @RequiresPermissions("busi:order:deliver")
    public Result deliver(@RequestBody BusiOrderDTO dto){
        //效验数据
        busiOrderService.deliver(dto);
        return new Result();
    }

    //
//    @PostMapping
//    @ApiOperation("保存")
//    @LogOperation("保存")
////    @RequiresPermissions("busi:order:save")
//    public Result save(@RequestBody @Validated BusiOrderDTO dto){
//        //效验数据
//        ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);
//        busiOrderService.saveOrder(dto);
//        return new Result();
//    }
//
//
//    @DeleteMapping
//    @ApiOperation("删除")
//    @LogOperation("删除")
////    @RequiresPermissions("busi:order:delete")
//    public Result delete(@RequestBody Long[] ids){
//        //效验数据
//        AssertUtils.isArrayEmpty(ids, "id");
//        busiOrderService.delete(ids);
//        return new Result();
//    }
//
//    @GetMapping("export")
//    @ApiOperation("导出")
//    @LogOperation("导出")
////    @RequiresPermissions("busi:order:export")
//    public void export(@ApiIgnore @RequestParam Map<String, Object> params, HttpServletResponse response) throws Exception {
//        List<BusiOrderDTO> list = busiOrderService.list(params);
//        ExcelUtils.exportExcelToTarget(response, null, list, BusiOrderExcel.class);
//    }

}
